<?php

/**
 * solicitud actions.
 *
 * @package    courier
 * @subpackage solicitud
 * @author     Your name here
 */
class solicitudActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->Solicituds = SolicitudPeer::doSelect(new Criteria());
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->Solicitud = SolicitudPeer::retrieveByPk($request->getParameter('sol_id'));
    $this->forward404Unless($this->Solicitud);
  }

  public function executeShowSolicitud(sfWebRequest $request)
  {
    $this->Cliente = ClientePeer::retrieveByPk($request->getParameter('cli_id'));
    $this->forward404Unless($this->Cliente);
  }

 public function executeShowSol(sfWebRequest $request)
  {
    $this->Cliente = ClientePeer::retrieveByPk($request->getParameter('cli_id'));
    $this->forward404Unless($this->Cliente);
  }

  public function executeUpdateStatus(sfWebRequest $request)
  {
    $this->Solicitud = SolicitudPeer::retrieveByPk($request->getParameter('sol_id'));
    $this->forward404Unless($this->Solicitud);
  }

 public function executeAsignarsolicitud(sfWebRequest $request)
  {
	$this -> setLayout('pop');     
	$this->Empleados = EmpleadoPeer::doSelect(new Criteria());
        $this->sol_id=$request->getParameter('sol_id');

  }

public function executeAspa(sfWebRequest $request)
  {
	$this->Solicitud = SolicitudPeer::retrieveByPk($request->getParameter('sol_id'));
	$this->Solicitud->setSolEmprecolector($request->getParameter('combo'));
	$this->Solicitud->setSolEstado('Recolectada');
	$this->Solicitud->save();
	$this->sol_id=$request->getParameter('sol_id');
  }

  public function executeNew(sfWebRequest $request)
  {
	if ($request->getParameter('cli_id') != null){
		$identificadorCliente = new Solicitud();
		$identificadorCliente->setSolCliente($request->getParameter('cli_id'));
		$this->form = new SolicitudForm($identificadorCliente);
	}
	else{
		$this->form = new SolicitudForm();
	}
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new SolicitudForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($Solicitud = SolicitudPeer::retrieveByPk($request->getParameter('sol_id')), sprintf('Object Solicitud does not exist (%s).', $request->getParameter('sol_id')));
    $this->form = new SolicitudForm($Solicitud);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($Solicitud = SolicitudPeer::retrieveByPk($request->getParameter('sol_id')), sprintf('Object Solicitud does not exist (%s).', $request->getParameter('sol_id')));
    $this->form = new SolicitudForm($Solicitud);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($Solicitud = SolicitudPeer::retrieveByPk($request->getParameter('sol_id')), sprintf('Object Solicitud does not exist (%s).', $request->getParameter('sol_id')));
    $Solicitud->delete();

    $this->redirect('solicitud/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {

      $Solicitud = $form->save();
      $this->redirect('paquete/new?sol_id='.$Solicitud->getSolId());	
     
    }
  }
}
